package exttable.testversioning.testversioncreate;

import exttable.testversioning.IDBUtils;
import exttable.testversioning.TestVersioningDBUtils;
import exttable.testversioning.tablemodel.AnalysisVersionModel;
import exttable.view.ViewAnalysis;
import exttable.view.ViewAnalysisParameter;
import exttable.view.ViewVersion;

import java.util.Vector;

/**
 * Created by IntelliJ IDEA.
 * User: Admin
 * Date: Aug 6, 2010
 * Time: 4:55:01 PM
 * To change this template use File | Settings | File Templates.
 */
public class CreateAVModel {
    private IDBUtils dataService;
    private Vector<ViewAnalysisParameter> editedTableData;
    private Vector<ViewAnalysisParameter> originalTableData;
    private AnalysisVersionModel versionModel;
    private ViewAnalysis viewAnalysis;


    public CreateAVModel(ViewAnalysis viewAnalysis) throws Exception {
        this.viewAnalysis = viewAnalysis;
        originalTableData = new Vector<ViewAnalysisParameter>();
        editedTableData = new Vector<ViewAnalysisParameter>();
        dataService = new TestVersioningDBUtils();
        versionModel = new AnalysisVersionModel(viewAnalysis.getAnalysisId());
        setOriginalTableModel(viewAnalysis);
    }

    public ViewVersion getVersionAnalysis() throws Exception {
        return dataService.getVersion(viewAnalysis.getAnalysisId());
    }

    public Vector<ViewAnalysisParameter> getEditedTableData() {
        return editedTableData;
    }

    public Vector<ViewAnalysisParameter> getOriginalTableData() {
        return originalTableData;
    }

    public void setOriginalTableModel(ViewAnalysis viewAnalysis) {
        AnalysisVersionModel avm = new AnalysisVersionModel(viewAnalysis.getAnalysisId());
        originalTableData.addAll(avm.getData());
    }

    public AnalysisVersionModel getVersionModel() {
        return versionModel;
    }

    public IDBUtils getDataService() {
        return dataService;
    }

    public ViewAnalysis getViewAnalysis() {
        return viewAnalysis;
    }

}
